package controller

import (
	myConfig "common/config"
	"common/helper"
	"fmt"
	"github.com/valyala/fasthttp"
	"member/model"
)

type ConfigController struct{}

func (that ConfigController) WeekDepositReturn(ctx *fasthttp.RequestCtx) {

	var cfg myConfig.CsDepositReturnCfg

	data := cfg.GetCfg()
	helper.Print(ctx, true, data)
}

func (that ConfigController) WeekLostReturn(ctx *fasthttp.RequestCtx) {

	var cfg myConfig.CsLostReturnCfg

	data := cfg.GetCfg()
	helper.Print(ctx, true, data)
}

func (that ConfigController) DailyRunningReturn(ctx *fasthttp.RequestCtx) {

	var cfg myConfig.CsDailyRunningReturnCfg

	data := cfg.GetCfg()
	helper.Print(ctx, true, data)
}

func (that ConfigController) WeekRunningReturn(ctx *fasthttp.RequestCtx) {

	var cfg myConfig.CsRunningReturnCfg

	data := cfg.GetCfg()
	helper.Print(ctx, true, data)
}
func (that ConfigController) WeekProxyCommiReturn(ctx *fasthttp.RequestCtx) {

	var cfg myConfig.CsProxyCommiReturnCfg

	data := cfg.GetCfg()
	helper.Print(ctx, true, data)
}

// 累计充值奖励配置
func (that ConfigController) AccuDepositBonus(ctx *fasthttp.RequestCtx) {

	var cfg myConfig.CsAccuDepositBonusCfg

	data := cfg.GetCfg()

	helper.Print(ctx, true, data)
}

func (that ConfigController) ActiveSwitchCfg(ctx *fasthttp.RequestCtx) {
	data := myConfig.GetActiveSwitchCfg()
	helper.Print(ctx, true, data)
}

func (that ConfigController) ProxyInviteBonusByAmount(ctx *fasthttp.RequestCtx) {
	var cfg myConfig.CsProxyInviteBonusCfg
	data := cfg.GetDepoistAmountCfg()
	helper.Print(ctx, true, data)
}

func (that ConfigController) ProxyInviteBonus(ctx *fasthttp.RequestCtx) {
	var cfg myConfig.CsProxyInviteBonusCfg
	data := cfg.GetCfg()
	helper.Print(ctx, true, data)
}

func (that ConfigController) Announcement(ctx *fasthttp.RequestCtx) {

	data := myConfig.GetCfgAnnouncement()
	helper.Print(ctx, true, data)
}

/*
获取充值分成比例
*/

type RechargeShareCfg struct {
	Level int     `db:"level" json:"level"`
	Rate  float64 `db:"rate" json:"rate"`
}

type RechargeShareList struct {
	CfgList        []RechargeShareCfg `json:"cfgList"`
	ValidUserWaged float64            `json:"validWaged"`
	Lv1FlowMul     float64            `json:"Lv1FlowMul"`
	Lv2FlowMul     float64            `json:"Lv2FlowMul"`
	Lv3FlowMul     float64            `json:"Lv3FlowMul"`
}

func (that ConfigController) GetRechargeShareCfg(ctx *fasthttp.RequestCtx) {
	var cfglist RechargeShareList
	sqlSelect := fmt.Sprint("select level,rate from tbl_cfg_recharge_share_rate order by level asc ")
	model.GetMasterDBInstance().Select(&cfglist.CfgList, sqlSelect)

	cfglist.ValidUserWaged = myConfig.GetGameCfgFloat64(myConfig.CfgRechargeShareWagedReq)
	cfglist.Lv1FlowMul = myConfig.GetFlowMul(0, helper.TransactionRechargeShareBonuslv1)
	cfglist.Lv2FlowMul = myConfig.GetFlowMul(0, helper.TransactionRechargeShareBonuslv2)
	cfglist.Lv3FlowMul = myConfig.GetFlowMul(0, helper.TransactionRechargeShareBonuslv3)
	helper.Print(ctx, true, cfglist)
}

type BackUpWeb struct {
	Web       string `json:"u"`
	WebSwitch int    `json:"b"`
}

func (that ConfigController) GameConfig(ctx *fasthttp.RequestCtx) {
	var rsp ApiLink
	rsp.Telegram = myConfig.GetGameCfgString(myConfig.CfgTelegramLink)
	rsp.Facebook = myConfig.GetGameCfgString(myConfig.CfgFacebookLink)
	rsp.Twitter = myConfig.GetGameCfgString(myConfig.CfgTwitterLink)
	rsp.Instagram = myConfig.GetGameCfgString(myConfig.CfgInstagramLink)
	rsp.AppDownloadBonus = myConfig.GetGameCfgString(myConfig.CfgAppDownloadBonus)

	rsp.ValidInviteWagedReq = myConfig.GetGameCfgFloat64(myConfig.CfgValidInviteWagedReq)
	rsp.ValidInviteMinDeposit = myConfig.GetGameCfgFloat64(myConfig.CfgValidInviteMinDeposit)
	rsp.ValidInviteCondition = myConfig.GetGameCfgInt(myConfig.CfgValidInviteCondition)
	rsp.CfgWithdrawPixType = myConfig.GetGameCfgInt(myConfig.CfgWithdrawPixType)
	rsp.CfgDepositCPFSwitch = myConfig.GetGameCfgInt(myConfig.CfgDepositCPFSwitch)

	rsp.ReturnLevelOneRate = myConfig.GetGameCfgString(myConfig.CfgChildWagedReturnLevelOneRate)
	rsp.ReturnLevelTwoRate = myConfig.GetGameCfgString(myConfig.CfgChildWagedReturnLevelTwoRate)
	rsp.ReturnLevelThreeRate = myConfig.GetGameCfgString(myConfig.CfgChildWagedReturnLevelThreeRate)
	rsp.ReturnCalcHour = myConfig.GetGameCfgString(myConfig.CfgChildWagedReturnCalcHour)

	/*
		rsp.CfgMainWeb = ""
		var BackUpWebList []BackUpWeb
		CfgJsonString := myConfig.GetGameCfgString(myConfig.CfgMainWeb)
		err := json.Unmarshal([]byte(CfgJsonString), &BackUpWebList)
		if err == nil {
			for _, item := range BackUpWebList {
				if item.WebSwitch == 1 {
					if rsp.CfgMainWeb != "" {
						rsp.CfgMainWeb += ","
					}

					rsp.CfgMainWeb += item.Web
				}
			}
		}
	*/

	rsp.CfgMainWeb = helper.GetSourceFromRequest(ctx)
	helper.Print(ctx, true, rsp)
}

type ApiLink struct {
	Telegram              string  `json:"telegram"`
	Facebook              string  `json:"facebook"`
	Twitter               string  `json:"twitter"`
	Instagram             string  `json:"instagram"`
	AppDownloadBonus      string  `json:"AppDownloadBonus"`
	ValidInviteWagedReq   float64 `json:"ValidInviteWagedReq"`
	ValidInviteMinDeposit float64 `json:"ValidInviteMinDeposit"`
	ValidInviteCondition  int     `json:"valid_invite_condition"`
	CfgWithdrawPixType    int     `json:"CfgWithdrawPixType"`
	CfgDepositCPFSwitch   int     `json:"cfg_deposit_cpf_switch"`
	CfgMainWeb            string  `json:"MainWeb"`
	ReturnLevelOneRate    string  `json:"return_level_one_rate"`
	ReturnLevelTwoRate    string  `json:"return_level_two_rate"`
	ReturnLevelThreeRate  string  `json:"return_level_three_rate"`
	ReturnCalcHour        string  `json:"return_calc_hour"`
}

func (that ConfigController) BroadcastConfig(ctx *fasthttp.RequestCtx) {

	var cfg myConfig.CsBroadcastCfg

	data := cfg.GetCfg()
	helper.Print(ctx, true, data)
}
func (that ConfigController) GetVipList(ctx *fasthttp.RequestCtx) {
	data := myConfig.GetVipCfg()
	helper.Print(ctx, true, data)
}

func (that ConfigController) SuspensionImages(ctx *fasthttp.RequestCtx) {

	data := myConfig.GetCfgSuspensionImages()
	helper.Print(ctx, true, data)
}

type ActiveSwitchList struct {
	SwitchCfg           []myConfig.ActiveSwitchCfg     `json:"switch_cfg"`
	SuspensionImagesCfg []myConfig.CfgSuspensionImages `json:"suspension_images_cfg"`
}

func (that ConfigController) ActiveSwitchList(ctx *fasthttp.RequestCtx) {
	var data ActiveSwitchList
	data.SwitchCfg = myConfig.GetActiveSwitchCfg()
	data.SuspensionImagesCfg = myConfig.GetCfgSuspensionImages()
	helper.Print(ctx, true, data)
}
